package common

import (
	"os"

	log "github.com/sirupsen/logrus"
)

var (
	stdLog  *log.Logger
	fileLog *log.Logger
)

func init() {
	stdLog = log.New()
	fileLog = log.New()
	stdLog.SetLevel(log.InfoLevel)
	fileLog.SetLevel(log.InfoLevel)
	stdLog.SetOutput(os.Stdout)
	fileLog.SetOutput(GetFile("log.log"))

}

type logLevel int

const (
	ERROR = iota
	INFO
)

func Log(msg any, extField map[string]any, level logLevel) {
	if level == INFO {
		stdLog.WithFields(extField).Info(msg)
		fileLog.WithFields(extField).Info(msg)
	} else {
		stdLog.WithFields(extField).Error(msg)
		fileLog.WithFields(extField).Error(msg)
	}
}

func LogInfo(msg string) {
	Log(msg, nil, INFO)
}
func LogError(msg string) {
	Log(msg, nil, ERROR)
}

func LogInfoWithData(msg string, extField map[string]any) {
	Log(msg, extField, INFO)
}

func LogErrorWithData(msg string, extField map[string]any) {
	Log(msg, extField, ERROR)
}
